package com.seecoder.BlueWhale.controller;

import com.seecoder.BlueWhale.service.ImageService;
import com.seecoder.BlueWhale.util.SecurityUtil;
import com.seecoder.BlueWhale.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/api")
public class ToolsController {
    @Autowired
    ImageService imageService;
    @Autowired
    SecurityUtil securityUtil;

    @PostMapping("/images")
    public ResultVO<String> upload(@RequestParam MultipartFile file){
        log.warn("User[{}] begins to upload image", securityUtil.getUserId());
        ResultVO<String> ans = ResultVO.buildSuccess(imageService.upload(file));
        log.warn("User[{}] ends to upload image", securityUtil.getUserId());
        return ans;
    }

}
